﻿using System;
using System.Reflection;
using System.Web.UI.WebControls;
using System.Linq;
using BoldBrick.SharePoint.CommonControls.Extensions;

namespace BoldBrick.SharePoint.CommonControls.Layouts
{
	public class DialogMaster : Microsoft.SharePoint.WebControls.DialogMaster
	{
		#region ------ Controls -------------------------------------------------------------------

		public Button CancelButton;
		protected Literal literalDescription;
		protected Image dialogIconImage;

		#endregion

		#region ------ Properties -----------------------------------------------------------------

		/// <summary>
		/// Desciption of the dialog
		/// </summary>
		public string Description
		{
			get { return literalDescription.Text; }
			set { literalDescription.Text = value; }
		}

		/// <summary>
		/// Gets/sets icon for dialog
		/// </summary>
		public DialogIconTypes DialogIconType
		{
			get { return GetDialogIconType(); }
			set { SetDialogIconType(value); }
		}

		private DialogIconTypes GetDialogIconType()
		{
			return DialogIconTypes.Dialog;
		}

		private void SetDialogIconType(DialogIconTypes value)
		{
			ImageUrlAttribute imageUrlAttribute = value.GetAttribute<ImageUrlAttribute>();
			if (imageUrlAttribute != null)
			{
				this.dialogIconImage.ImageUrl = imageUrlAttribute.Url;
			}
		}

		#endregion
	}

	/// <summary>
	/// Enum for dialog icon type
	/// </summary>
	public enum DialogIconTypes
	{
		[ImageUrl("/_layouts/images/erroricon.png")]
		Error,
		[ImageUrl("/_layouts/images/lg_ICHLP.gif")]
		Question,
		[ImageUrl("/_layouts/images/detail.gif")]
		Dialog
	}

	/// <summary>
	/// Attribute for image URL of dialog icon
	/// </summary>
	public class ImageUrlAttribute : Attribute
	{
		public string Url { get; set; }

		public ImageUrlAttribute(string url)
		{
			this.Url = url;
		}
	}
}
